#include<bits/stdc++.h>
using namespace std;

int const N = 200009;

int T,n,maxx;
int a[N],c[N],dp[N][N];
bool coled[N];

int col(int pos){
    int col;
    coled[pos] = 1;
    for(int i = pos;i>0;i--){
        if(a[pos] == a[i] && coled[i] == 1){
            col = a[pos];
            return col;
        }
    }

    coled[pos] = 0;
    return 0;
}


void solve(int dep,int nowans){
    if(dep>=n){
        maxx = max(maxx,nowans);
    }
    for(int i = 1;i<=n;i++){
        coled[i] = true;
        solve(dep++,nowans+col(i));
    }

}

int main(){

    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);

    memset(coled,0,sizeof(coled));
    scanf("%d",&T);
    for(int i = 1;i<=T;i++){
        scanf("%d",&n);
        for(int j = 1;j<=n;j++){
            scanf("%d",&a[j]);
        }
        solve(1,0);
    }
    return 0;
}

